#ifndef TCPSERVER_H
#define TCPSERVER_H

#pragma once
#include <QTcpServer>
#include <QTcpSocket>
#include<QMap>

class TcpSocket: public QTcpSocket
{
    Q_OBJECT
public:
    TcpSocket(int socketdesc,QTcpSocket *parent=NULL);
    ~TcpSocket();
signals:
    void signal_recv_data(QByteArray byte,QString ip);

private slots:
    void ReadAndParseData();
    void SocketError(QAbstractSocket::SocketError socketError);

private:
    QString m_recvDataStr;
};


class TcpServer : public QTcpServer
{
    Q_OBJECT
public:
    TcpServer(const QString ip,int port,QTcpServer *parent=NULL);
    ~TcpServer();
    TcpSocket socket(int index) const { m_socketList.at(index);}
protected:
    void incomingConnection(qintptr socketDescriptor);

private slots:
    void SocketDisconn();

private:
    QList<TcpSocket*> m_socketList;
};

#endif // TCPSERVER_H
